<?php
namespace Tbf\Bundle\ImageBundle;

use Tbf\Bundle\UploadBundle\BlobInterface;
use Tbf\Bundle\UploadBundle\error;
use Tbf\Bundle\UploadBundle\MemoryBlob;
use Tbf\Bundle\UploadBundle\TransformerInterface;

class QualityChangeTransformer implements TransformerInterface
{
    protected $quality;
    public function __construct($quality)
    {
        $this->quality = $quality;
    }
    /**
     * @param  BlobInterface $input
     * @return BlobInterface $output
     * @return error
     */
    public function transform(BlobInterface $input)
    {
        list($content,$err) = $input->getContent();
        if ($err!==null) {
            return array(null,$err);
        }
        $image = \WideImage::loadFromString($content);
        $after_content = $image->asString('jpg',$this->quality);

        return array(new MemoryBlob($after_content,'jpg'),null);
    }

}
